/**
 * Created by smp on 2017/6/7.
 */

var modelPath=ROOT_PATH+'/observation/observationCard/';
/**
 * 成功回掉事件
 * @param data
 */
function successCallback(data){

    if(data.success){
        layer.msg(data.message,{time:1000,icon:1},function () {
            WindowManager.closeLayer({
                returnValue:''
            });
        });

    }else{
        layer.msg(data.message,{time:1000,icon:2});
    }

}
function validColor() {
    var flag=true;
    $(".validColor").each(function () {
        var len=$(this).parent("li").siblings("li").children(".judgeT:checked").length;
        console.log(len);
        if(len==0){
            flag=false;
        }
    });
    return flag;
}

$('#cardSave').on('click',function () {
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        var fl=validColor();
        if(fl==false){
            layer.close(index);
            layer.msg('带*号的必填', {
                icon: 2,
                time: 2000
            });
            return;
        }
        $('#cardForm').form('submit', {
            url: ROOT_PATH+'/observation/observationCard/verify.shtml',
            onSubmit: function (param) {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    layer.close(index);
                    layer.msg("请正确填写表单")
                }
                return $(this).form('validate');
            },
            success: function (result) {
                var data = $.parseJSON(result);
                successCallback(data)
            }
        });
    });

});
//表单驳回
$('#cardBack').on('click',function () {
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        $('#cardForm').form('submit', {
            url: ROOT_PATH+'/observation/observationCard/reject.shtml',
            onSubmit: function (param) {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    layer.close(index);
                    layer.msg("请正确填写表单")
                }
                return $(this).form('validate');
            },
            success: function (result) {
                var data = $.parseJSON(result);
                successCallback(data)
            }
        });
    });

});